package main

import (
	"fmt"
	"github.com/gomodule/redigo/redis"
)

var pool *redis.Pool

func init() {
	fmt.Println("init redis pool...")
	pool = &redis.Pool{
		MaxIdle:     16,   //最大空闲连接数
		MaxActive:   1024, //最大激活连接数
		IdleTimeout: 300,  //空闲连接最大等待时间
		Dial: func() (redis.Conn, error) { //获取连接方法
			return redis.Dial("tcp", "localhost:6379")
		},
	}
}

func main() {
	conn := pool.Get()
	defer conn.Close()

	conn.Do("set", "key3", "val3")
	ret, _ := redis.String(conn.Do("get", "key3"))
	fmt.Println(ret)
}
